var _n84;
var cc__extends = __extends;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $miniGameApiBase = require("miniGameApiBase");
var s = window.wx;
var def_wxApi = function (t) {
  function _ctor() {
    var e = null !== t && t.apply(this, arguments) || this;
    e.m_AppId = "";
    e.m_Secret = "";
    e.m_VideoAdIdIndex = 0;
    e.m_VideoAdIdList = ["adunit-7ad7b2318d17f202"];
    e.m_BannerAdIdIndex = 0;
    e.m_BannerAdId = [];
    e.m_InsertAdIdIndex = 0;
    e.m_InsertAdId = [];
    e.m_videoAd = undefined;
    e.m_BannerAd = undefined;
    e.m_gameRecorder = null;
    e.m_gameRecordDate = 0;
    e.m_gameRecordUrl = undefined;
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.FullScreenVideoAd = function () {};
  _ctor.prototype.validAppId = function () {
    cc.log("测试修改");
  };
  _ctor.prototype.ready = function () {
    var t = this;
    console.log("wx-api");
    if (window.ks) {
      var e = window.ks.getGameRecorder();
      this.m_gameRecorder = e;
      e.on("start", function () {});
      e.on("error", function () {});
      e.on("stop", function (e) {
        if (e && e.videoID) {
          console.log("videoID is " + e.videoID);
          t.m_gameRecordUrl = e.videoID;
          console.log("录屏停止，录制成功");
        } else {
          console.log("录屏停止，录制失败");
        }
      });
      e.on("pause", function () {
        console.log("暂停录制");
      });
      e.on("resume", function () {
        console.log("继续录制");
      });
      e.on("abort", function () {
        console.log("废弃已录制视频");
      });
    }
    if (!window.ks) {
      s.showShareMenu({
        withShareTicket: true,
        success() {
          console.log("设置分享成功");
        },
        fail() {},
        complete() {}
      });
      s.onShareAppMessage(function () {
        return {
          title: "",
          imageUrl: ""
        };
      });
    }
  };
  _ctor.prototype.getUserInfo = function (t) {
    s.getUserInfo(t);
  };
  _ctor.prototype.showToast = function (t) {
    s.showToast(t);
  };
  _ctor.prototype.showLoading = function (t) {
    s.showLoading(t);
  };
  _ctor.prototype.hideLoading = function () {
    s.hideLoading();
  };
  _ctor.prototype.showModal = function (t) {
    s.showModal(t);
  };
  _ctor.prototype.authorize = function (t) {
    t.success && t.success();
  };
  _ctor.prototype.login = function (t) {
    s.login(t);
  };
  _ctor.prototype.getVideoAdId = function () {
    var t = this.m_VideoAdIdList[this.m_VideoAdIdIndex];
    this.m_VideoAdIdIndex++;
    this.m_VideoAdIdIndex >= this.m_VideoAdIdList.length && (this.m_VideoAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.loadAndShowVideoAd = function (t, e, o, n, i) {
    var a = this;
    undefined === i && (i = "game_use_prop");
    if (window["GM-mode"]) {
      t();
    } else {
      var c = this.getVideoAdId();
      window.ks && (c = "2300005486_01");
      if (c) {
        this.showLoading({
          title: "请求中",
          mask: true
        });
        console.log("tt 视频广告", c, n);
        var l = s.createRewardedVideoAd({
          adUnitId: c
        });
        var u = function u(s) {
          l.offClose(u);
          console.log("tt 视频广告关闭", s);
          if (s && s.isEnded) {
            setTimeout(function () {
              t();
              a.reportAnalytics(i, n);
            }, 60);
          } else {
            e("视频中途退出");
          }
          var c = !(!s || !s.isEnded);
          a.reportAd(c);
          o && o();
          $zqcc_OverallSystem.mgrs().soundMgr.isPlayMusic && $zqcc_OverallSystem.mgrs().soundMgr.playMusic($zqcc_OverallSystem.mgrs().soundMgr.shangyige);
        };
        console.log("展示一次");
        l.load().then(function () {
          l.show().then(function () {
            a.hideLoading();
            l.onClose(u);
          }).catch(function () {
            console.log("重试一次");
            l.load().then(function () {
              l.show().then(function () {
                a.hideLoading();
                l.onClose(u);
              }).catch(function () {
                e && e("视频展示异常");
                o && o();
              });
            }).catch(function () {
              e && e("视频拉取异常02");
              o && o();
            });
          });
        }).catch(function () {
          e && e("视频拉取异常01");
          o && o();
        });
        l.onError(function (t) {
          console.log(t);
          a.hideLoading();
        });
      } else {
        t();
      }
    }
  };
  _ctor.prototype.getInsertAdId = function () {
    var t = this.m_InsertAdId[this.m_InsertAdIdIndex];
    this.m_InsertAdIdIndex++;
    this.m_InsertAdIdIndex >= this.m_InsertAdId.length && (this.m_InsertAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.showInsertAd = function (t, e) {
    console.log("加抖音 插屏 广告");
    var o = this.getInsertAdId();
    var n = s.createInterstitialAd({
      adUnitId: o
    });
    n.load();
    n.onLoad(function () {
      console.warn("插屏广告 加载完成");
      n.show().catch(function (t) {
        console.warn("插屏广告 显示失败 :" + JSON.stringify(t));
        n.destroy();
        n = null;
        e && e();
      });
    });
    n.onError(function (t) {
      console.warn("插屏广告 加载失败" + JSON.stringify(t));
      n.destroy();
      n = null;
      e && e();
    });
    n.onClose(function () {
      console.warn("插屏广告 关闭");
      if (null != n) {
        n.destroy();
        n = null;
      }
      t && t();
    });
  };
  _ctor.prototype.getBannerAdId = function () {
    var t = this.m_BannerAdId[this.m_BannerAdIdIndex];
    this.m_BannerAdIdIndex++;
    this.m_BannerAdIdIndex >= this.m_BannerAdId.length && (this.m_BannerAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.showBannerAD = function () {};
  _ctor.prototype.hideBanner = function () {};
  _ctor.prototype.recordedGameScreenStart = function () {
    this.m_gameRecorder && this.m_gameRecorder.start();
  };
  _ctor.prototype.recordedGameScreenStop = function () {
    return false;
  };
  _ctor.prototype.shareRecordedGameScreen = function (t, e) {
    if (this.m_gameRecordUrl) {
      this.m_gameRecorder.publishVideo({
        video: this.m_gameRecordUrl,
        callback(t) {
          if (null == t || null == t) {
            console.log("分享录屏成功");
          } else {
            console.log("分享录屏失败: " + JSON.stringify(t));
          }
        }
      });
    } else {
      e && e(null);
      console.log("tt 分享视频为空");
    }
  };
  _ctor.prototype.isHaveRecordedGameScreen = function () {
    return true;
  };
  _ctor.prototype.reportAnalytics = function (t, e) {
    var o = window.SEEG_USER_INFO;
    var n = "";
    if (o) {
      if (11 === o.abTest) {
        n = "wx_B_";
      } else {
        10 === o.abTest && (n = "wx_A_");
      }
    }
    var i = n + t;
    e.level && (i = i + "_" + e.level);
    if (!(e.level && e.level > 40)) {
      console.log("埋点");
      console.log(i);
      console.log(e);
      seeg.onEvent(i, e);
    }
  };
  _ctor.prototype.reportAd = function (t) {
    if (window.ks) {
      var e = {
        complete: t
      };
      console.log("快手");
      console.log(e);
      seeg.reportAd(e);
    }
  };
  _ctor.prototype.vibrateShort = function (t, e) {
    undefined === t && (t = true);
    undefined === e && (e = "medium");
    if ($zqcc_OverallSystem.mgrs().soundMgr.isVibration) {
      cc.log("震动" + e);
      if (cc.sys.platform != cc.sys.VIVO_GAME && cc.sys.platform != cc.sys.OPPO_GAME && window.wx && window.wx.vibrateShort) {
        if (t) {
          window.wx.vibrateLong({
            type: e,
            style: e
          });
        } else {
          window.wx.vibrateShort({
            type: e,
            style: e
          });
        }
      }
    }
  };
  _ctor.prototype.shareAppMessage = function (t, e, o) {
    var n = this;
    undefined === t && (t = "");
    undefined === e && (e = "");
    undefined === o && (o = null);
    if (o) {
      window.canvas.toTempFilePath({
        x: o.x,
        y: o.y,
        width: o.width,
        height: o.height,
        destWidth: o.destWidth,
        destHeight: o.destHeight,
        success(o) {
          n.wxShareAppMessage(t, e, o.tempFilePath);
        },
        fail(t) {
          cc.warn("截图失败:", t);
        }
      });
    } else {
      this.wxShareAppMessage(t, e, "");
    }
  };
  _ctor.prototype.wxShareAppMessage = function (t, e, o) {
    s.shareAppMessage({
      title: t,
      desc: e,
      imageUrl: o,
      query: "",
      success() {
        console.log("分享成功");
      },
      fail() {
        console.log("分享失败");
      }
    });
  };
  return _ctor;
}($miniGameApiBase.MiniGameApiBase);
exports.default = def_wxApi;